const Excel = require('exceljs')
const path = require('path')
module.exports = function (info) {
  const workBook = new Excel.Workbook()
  workBook.creator = 'wangxu'
  workBook.created = new Date()
  workBook.modified = new Date()
  workBook.lastPrinted = new Date()

  const sheet = workBook.addWorksheet(info.title)
  const indexList = info.index
  // add title
  sheet.addRow([info.title])
  // add headers
  const headers = ['序号']
  indexList.forEach((indexItem) => {
    headers.push(info.headers[indexItem])
  })
  sheet.addRow(headers)

  info.list.forEach((item, index) => {
    const row = [index + 1]
    indexList.forEach((indexItem) => {
      row.push(item[indexItem])
    })
    sheet.addRow(row)
  })
  return workBook.xlsx.writeFile(path.resolve(__dirname, `../${info.title}.xlsx`))
}
